package com.venus.controller.rest;

import com.github.pagehelper.PageInfo;
import com.venus.controller.MenuController;
import com.venus.entity.Menu;
import com.venus.entity.Page;
import com.venus.service.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by admin on 15/10/17.
 */
@Api(value="RESTful服务接口")
@RestController
@RequestMapping(value="/rest")
public class RestfulController {
	public static final Logger LOGGER = LoggerFactory.getLogger(MenuController.class);

	@Autowired
	private MenuService menuService;

	/**
	 * 获取所有父节点
	 * @return
	 */
	@ApiOperation(value="获取所有父节点", notes="获取所有父节点信息")
	@GetMapping("getAllParentNodeInfo")
	public List<Menu> getAllParentNodeInfo(){
		return menuService.getAllParentNodeInfo();
	}

	/**
	 * 获取全部菜单
	 * @return
	 */
	@ApiOperation(value="获取菜单分页列表", notes="获取菜单分页列表信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "menu", value = "查询条件", required = false, dataType = "com.venus.entity.Menu"),
			@ApiImplicitParam(name = "page", value = "分页参数", required = false, dataType = "com.venus.entity.Page")
	})
	@PostMapping(value = "getMenuListByPage")
	public Map<String,Object> getMenusByPageList(Menu menu, Page page){
		Map<String,Object> result = new HashMap<>();
		page.setObject(menu);
		try {
			PageInfo<Menu> pageInfo = menuService.findMenusByPageList(page);
			result.put("status","200");
			result.put("pageNum",pageInfo.getPageNum());
			result.put("pages",pageInfo.getPages());
			result.put("total",pageInfo.getTotal());
			result.put("list", pageInfo.getList());
		} catch(Exception e) {
			e.printStackTrace();
			result.put("status","500");
		}
		return result;
	}
}
